/**
 * @author Rodrigo Moreira Alexandre
 * @author Fernando Aparecido Paulo
 */
package br.com.regressao.linear.principal;

import br.com.regressao.linear.dao.DAOEixoX;
import br.com.regressao.linear.dao.DAOEixoY;
import br.com.regressao.linear.formulas.Calculo;
import br.com.regressao.linear.modelo.EixoX;
import br.com.regressao.linear.modelo.EixoY;
import br.com.regressao.linear.modelo.ItemEixoX;
import br.com.regressao.linear.modelo.ItemEixoXPK;
import br.com.regressao.linear.modelo.ItemEixoY;
import br.com.regressao.linear.modelo.ItemEixoYPK;
import br.com.regressao.linear.util.Util;
import com.zap.arca.util.WindowUtils;
import java.awt.event.KeyEvent;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import javax.swing.DefaultListModel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
 *
 * @author Rodrigo Moreira Alexandre
 * @author Fernando Aparecido Paulo
 */
public class TelaPrincipal extends javax.swing.JFrame {

    private Util util = new Util();
    private DefaultListModel listModelX = new DefaultListModel();
    private DefaultListModel listModelY = new DefaultListModel();
    private Calculo calculo = new Calculo();
    private ItemEixoX itemEixoX;
    private ItemEixoY itemEixoY;

    /**
     * Creates new form NewJFrame
     */
    //Colando ícone do canto do Jframe
    {
        WindowUtils.setIconApp(this, "/resources/imagens/chart.png");
        WindowUtils.setSystemLookAndFeel();
        new DAOEixoX().consultar(0);
    }

    public TelaPrincipal() {
        initComponents();

        WindowUtils.nextEnter(plCamposX);
        WindowUtils.nextEnter(plCamposY);
        WindowUtils.exitEsc(this);
        WindowUtils.setEnterButton(btAdicionarX);
        WindowUtils.setEnterButton(btAdicionarY);
        WindowUtils.setEnterButton(btSimularRegressao);
        WindowUtils.setEnterButton(btExecutar);
        listY.setModel(listModelY);
        listX.setModel(listModelX);

        configurarEvento();
        tfValorX.requestFocus();
        setLocation(40, 150);

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        jPanel2 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jPopupMenu1 = new javax.swing.JPopupMenu();
        plCampos = new javax.swing.JPanel();
        jtCoeficientes = new javax.swing.JTabbedPane();
        jPanel3 = new javax.swing.JPanel();
        btCancelar = new javax.swing.JButton();
        btExecutar = new javax.swing.JButton();
        jSplitPane1 = new javax.swing.JSplitPane();
        plCamposX = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        listX = new javax.swing.JList();
        btAdicionarX = new javax.swing.JButton();
        btRemoverX = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        tfValorX = new com.zap.arca.JADecimalFormatField();
        plCamposY = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        listY = new javax.swing.JList();
        btAdicionarY = new javax.swing.JButton();
        btRemoverY = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        tfValorY = new com.zap.arca.JADecimalFormatField();
        btUltimaLista = new javax.swing.JButton();
        btLimpar = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        plCamposX1 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        tfCoeficienteR = new com.zap.arca.JADecimalFormatField(9,4);
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        tfDeterminacao = new com.zap.arca.JADecimalFormatField(9,2);
        jLabel16 = new javax.swing.JLabel();
        tfRegressaoYeX = new com.zap.arca.JADecimalFormatField();
        jLabel12 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jLabel13 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        tfParamA1 = new com.zap.arca.JADecimalFormatField(9,4);
        jLabel19 = new javax.swing.JLabel();
        tfParamB1 = new com.zap.arca.JADecimalFormatField(9,4);
        jLabel20 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jLabel14 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        tfParamA = new com.zap.arca.JADecimalFormatField(9,4);
        jLabel15 = new javax.swing.JLabel();
        tfParamB = new com.zap.arca.JADecimalFormatField(9,4);
        jLabel17 = new javax.swing.JLabel();
        tfResultadoRegressaoX = new com.zap.arca.JADecimalFormatField();
        btSimularRegressao = new javax.swing.JButton();
        plCamposY1 = new javax.swing.JPanel();
        plCamposR = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTextPane2 = new javax.swing.JTextPane();

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        jLabel3.setText("jLabel3");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Regressão Linear Simples");
        setBackground(new java.awt.Color(51, 255, 255));
        setResizable(false);

        jtCoeficientes.setBackground(new java.awt.Color(204, 204, 204));

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));

        btCancelar.setText("Cancelar");
        btCancelar.setOpaque(false);
        btCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCancelarActionPerformed(evt);
            }
        });

        btExecutar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/imagens/chart.png"))); // NOI18N
        btExecutar.setText("Gerar Gráfico");
        btExecutar.setOpaque(false);
        btExecutar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btExecutarActionPerformed(evt);
            }
        });

        jSplitPane1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jSplitPane1.setDividerLocation(350);

        plCamposX.setBackground(new java.awt.Color(255, 255, 255));
        plCamposX.setBorder(javax.swing.BorderFactory.createTitledBorder("Eixo X"));

        jScrollPane1.setViewportView(listX);

        btAdicionarX.setBackground(new java.awt.Color(255, 255, 255));
        btAdicionarX.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/imagens/add.png"))); // NOI18N
        btAdicionarX.setText("Adicionar");
        btAdicionarX.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAdicionarXActionPerformed(evt);
            }
        });
        btAdicionarX.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                btAdicionarXKeyPressed(evt);
            }
        });

        btRemoverX.setBackground(new java.awt.Color(255, 255, 255));
        btRemoverX.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/imagens/delete.png"))); // NOI18N
        btRemoverX.setText("Remover");
        btRemoverX.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btRemoverXActionPerformed(evt);
            }
        });
        btRemoverX.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                btRemoverXKeyPressed(evt);
            }
        });

        jLabel1.setText("Valor X:");

        tfValorX.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfValorXActionPerformed(evt);
            }
        });
        tfValorX.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tfValorXKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tfValorXKeyReleased(evt);
            }
        });

        javax.swing.GroupLayout plCamposXLayout = new javax.swing.GroupLayout(plCamposX);
        plCamposX.setLayout(plCamposXLayout);
        plCamposXLayout.setHorizontalGroup(
            plCamposXLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(plCamposXLayout.createSequentialGroup()
                .addGroup(plCamposXLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(plCamposXLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(plCamposXLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE)
                            .addGroup(plCamposXLayout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(tfValorX, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                    .addGroup(plCamposXLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(btAdicionarX, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btRemoverX)))
                .addContainerGap())
        );
        plCamposXLayout.setVerticalGroup(
            plCamposXLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(plCamposXLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(plCamposXLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(tfValorX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE)
                .addGroup(plCamposXLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btAdicionarX)
                    .addComponent(btRemoverX))
                .addContainerGap())
        );

        jSplitPane1.setLeftComponent(plCamposX);

        plCamposY.setBackground(new java.awt.Color(255, 255, 255));
        plCamposY.setBorder(javax.swing.BorderFactory.createTitledBorder("Eixo Y"));

        jScrollPane2.setViewportView(listY);

        btAdicionarY.setBackground(new java.awt.Color(255, 255, 255));
        btAdicionarY.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/imagens/add.png"))); // NOI18N
        btAdicionarY.setText("Adicionar");
        btAdicionarY.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAdicionarYActionPerformed(evt);
            }
        });
        btAdicionarY.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                btAdicionarYKeyPressed(evt);
            }
        });

        btRemoverY.setBackground(new java.awt.Color(255, 255, 255));
        btRemoverY.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/imagens/delete.png"))); // NOI18N
        btRemoverY.setText("Remover");
        btRemoverY.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btRemoverYActionPerformed(evt);
            }
        });

        jLabel2.setText("Valor Y:");

        javax.swing.GroupLayout plCamposYLayout = new javax.swing.GroupLayout(plCamposY);
        plCamposY.setLayout(plCamposYLayout);
        plCamposYLayout.setHorizontalGroup(
            plCamposYLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(plCamposYLayout.createSequentialGroup()
                .addGroup(plCamposYLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(plCamposYLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(plCamposYLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE)
                            .addGroup(plCamposYLayout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(tfValorY, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                    .addGroup(plCamposYLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(btAdicionarY)
                        .addGap(19, 19, 19)
                        .addComponent(btRemoverY)))
                .addContainerGap())
        );
        plCamposYLayout.setVerticalGroup(
            plCamposYLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(plCamposYLayout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(plCamposYLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(tfValorY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE)
                .addGroup(plCamposYLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btAdicionarY)
                    .addComponent(btRemoverY))
                .addContainerGap())
        );

        jSplitPane1.setRightComponent(plCamposY);

        btUltimaLista.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/imagens/approve_notes.png"))); // NOI18N
        btUltimaLista.setText("Buscar Última Lista");
        btUltimaLista.setOpaque(false);
        btUltimaLista.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btUltimaListaActionPerformed(evt);
            }
        });

        btLimpar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/imagens/edit.png"))); // NOI18N
        btLimpar.setText("Limpar Lista");
        btLimpar.setOpaque(false);
        btLimpar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btLimparActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addComponent(btExecutar)
                .addGap(18, 18, 18)
                .addComponent(btUltimaLista, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btLimpar, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(20, 20, 20))
        );

        jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btCancelar, btExecutar, btLimpar, btUltimaLista});

        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jSplitPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 294, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btCancelar)
                    .addComponent(btExecutar)
                    .addComponent(btUltimaLista)
                    .addComponent(btLimpar))
                .addGap(14, 14, 14))
        );

        jPanel3Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btCancelar, btExecutar, btLimpar, btUltimaLista});

        jtCoeficientes.addTab("Regressão Linear Simples", jPanel3);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        plCamposX1.setBackground(new java.awt.Color(255, 255, 255));
        plCamposX1.setBorder(javax.swing.BorderFactory.createTitledBorder("Coeficientes e Equação"));

        jLabel5.setText("Correlação:");
        jLabel5.setToolTipText("Correlação (r)");

        tfCoeficienteR.setForeground(new java.awt.Color(153, 255, 0));
        tfCoeficienteR.setEnabled(false);
        tfCoeficienteR.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        tfCoeficienteR.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfCoeficienteRActionPerformed(evt);
            }
        });

        jLabel7.setText("Determinação:");
        jLabel7.setToolTipText("Determinação (R²):");

        jLabel8.setText("%");

        tfDeterminacao.setEnabled(false);
        tfDeterminacao.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        tfDeterminacao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfDeterminacaoActionPerformed(evt);
            }
        });

        jLabel16.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel16.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel16.setText("Valor Estimado (y):");

        tfRegressaoYeX.setEditable(false);
        tfRegressaoYeX.setBackground(new java.awt.Color(255, 255, 0));
        tfRegressaoYeX.setForeground(new java.awt.Color(0, 0, 204));
        tfRegressaoYeX.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        tfRegressaoYeX.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfRegressaoYeXActionPerformed(evt);
            }
        });

        jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/imagens/correlação.png"))); // NOI18N

        jLabel23.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/imagens/determinação_1.png"))); // NOI18N

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));
        jPanel4.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(204, 204, 204), 1, true));

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/imagens/RegressaoY.png"))); // NOI18N

        jLabel18.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel18.setText("=");

        tfParamA1.setToolTipText("Estimativa do Parâmetro (a)");
        tfParamA1.setEnabled(false);
        tfParamA1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        tfParamA1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfParamA1ActionPerformed(evt);
            }
        });

        jLabel19.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel19.setText("+");

        tfParamB1.setToolTipText("Estimativa do Parâmetro (b)");
        tfParamB1.setEnabled(false);
        tfParamB1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        tfParamB1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfParamB1ActionPerformed(evt);
            }
        });

        jLabel20.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel20.setText(".");

        jLabel21.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel21.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/imagens/X.png"))); // NOI18N

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel18, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tfParamA1, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel19)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tfParamB1, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel20, javax.swing.GroupLayout.PREFERRED_SIZE, 8, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel21)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel4Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel19, jLabel21});

        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel21, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel18)
                        .addComponent(tfParamA1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel19)
                        .addComponent(tfParamB1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel20))
                    .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(19, Short.MAX_VALUE))
        );

        jPanel4Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {tfParamA1, tfParamB1});

        jPanel4Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jLabel19, jLabel20, jLabel21});

        jPanel5.setBackground(new java.awt.Color(255, 255, 255));
        jPanel5.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(204, 204, 204), 1, true));

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel14.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/imagens/RegressaoY.png"))); // NOI18N

        jLabel22.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel22.setText("=");

        tfParamA.setToolTipText("Estimativa do Parâmetro (a)");
        tfParamA.setEnabled(false);
        tfParamA.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        tfParamA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfParamAActionPerformed(evt);
            }
        });

        jLabel15.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel15.setText("+");

        tfParamB.setToolTipText("Estimativa do Parâmetro (b)");
        tfParamB.setEnabled(false);
        tfParamB.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        tfParamB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfParamBActionPerformed(evt);
            }
        });

        jLabel17.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel17.setText(".");

        tfResultadoRegressaoX.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        tfResultadoRegressaoX.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfResultadoRegressaoXActionPerformed(evt);
            }
        });
        tfResultadoRegressaoX.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tfResultadoRegressaoXKeyReleased(evt);
            }
        });

        btSimularRegressao.setText("Estimar");
        btSimularRegressao.setOpaque(false);
        btSimularRegressao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSimularRegressaoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btSimularRegressao, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel22)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tfParamA, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel15)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tfParamB, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel17, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tfResultadoRegressaoX, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(37, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel22)
                        .addComponent(tfParamA, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel15)
                        .addComponent(tfParamB, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel17)
                        .addComponent(tfResultadoRegressaoX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
                .addComponent(btSimularRegressao, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel5Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {tfParamA, tfResultadoRegressaoX});

        javax.swing.GroupLayout plCamposX1Layout = new javax.swing.GroupLayout(plCamposX1);
        plCamposX1.setLayout(plCamposX1Layout);
        plCamposX1Layout.setHorizontalGroup(
            plCamposX1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(plCamposX1Layout.createSequentialGroup()
                .addGap(4, 4, 4)
                .addGroup(plCamposX1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(plCamposX1Layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel23))
                    .addGroup(plCamposX1Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel12)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(plCamposX1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(plCamposX1Layout.createSequentialGroup()
                        .addComponent(tfDeterminacao, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel8))
                    .addComponent(tfCoeficienteR, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(plCamposX1Layout.createSequentialGroup()
                .addGroup(plCamposX1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, plCamposX1Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(jLabel16, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(tfRegressaoYeX, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(70, 70, 70))
        );

        plCamposX1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {tfCoeficienteR, tfDeterminacao});

        plCamposX1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel5, jLabel7});

        plCamposX1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel12, jLabel23});

        plCamposX1Layout.setVerticalGroup(
            plCamposX1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(plCamposX1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(plCamposX1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(plCamposX1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel12, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel5))
                    .addComponent(tfCoeficienteR, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(plCamposX1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(plCamposX1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel7)
                        .addComponent(jLabel8)
                        .addComponent(tfDeterminacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel23))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(plCamposX1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfRegressaoYeX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        plCamposX1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jLabel5, jLabel7});

        plCamposX1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jLabel12, jLabel23});

        plCamposX1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {tfCoeficienteR, tfDeterminacao});

        plCamposY1.setBackground(new java.awt.Color(255, 255, 255));
        plCamposY1.setBorder(javax.swing.BorderFactory.createTitledBorder("Fórmulas"));

        plCamposR.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/imagens/correlaçãoR.png"))); // NOI18N
        plCamposR.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                plCamposRMouseReleased(evt);
            }
        });
        plCamposR.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                plCamposRKeyPressed(evt);
            }
        });

        jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/imagens/determinação.png"))); // NOI18N
        jLabel6.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jLabel6MouseReleased(evt);
            }
        });

        jLabel9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/imagens/paramB.png"))); // NOI18N

        jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/imagens/paramA - Cópia.png"))); // NOI18N

        jLabel11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/imagens/Y.png"))); // NOI18N

        javax.swing.GroupLayout plCamposY1Layout = new javax.swing.GroupLayout(plCamposY1);
        plCamposY1.setLayout(plCamposY1Layout);
        plCamposY1Layout.setHorizontalGroup(
            plCamposY1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, plCamposY1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(plCamposY1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel11)
                    .addComponent(jLabel10)
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 292, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(170, 170, 170))
            .addGroup(plCamposY1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel9)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(plCamposY1Layout.createSequentialGroup()
                .addComponent(plCamposR, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        plCamposY1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel10, jLabel11, jLabel6, jLabel9, plCamposR});

        plCamposY1Layout.setVerticalGroup(
            plCamposY1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(plCamposY1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(plCamposR, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(33, Short.MAX_VALUE))
        );

        plCamposY1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jLabel10, jLabel11, jLabel6, jLabel9, plCamposR});

        plCamposR.getAccessibleContext().setAccessibleDescription("");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(plCamposX1, javax.swing.GroupLayout.PREFERRED_SIZE, 345, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(plCamposY1, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(plCamposY1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(plCamposX1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        jtCoeficientes.addTab("Cálculos", new javax.swing.ImageIcon(getClass().getResource("/resources/imagens/estatistica.png")), jPanel1); // NOI18N

        jPanel6.setBackground(new java.awt.Color(255, 255, 255));

        jTextPane2.setFont(new java.awt.Font("Cambria Math", 0, 14)); // NOI18N
        jTextPane2.setText("                                           ########## Coeficiente de Correlação: ##########\n\nO coeficiente de correlação linear de Pearson, serve para quantificar a intensidade da associação linear existente entra as variáveis.\nOs valores  das variáveis nunca serão menores que -1 e nunca maiores que 1. Intervalo: (-1 ≤ r ≤ +1):\n\n                                  Valor de r (positivo ou negativo)                  Interpretação\n\t          0,00 |---------------------------0,19          Uma correlação bem fraca\n\t          0,20 |---------------------------0,39          Uma correlação fraca\n\t          0,40 |---------------------------0,69          Uma correlação moderada\n                                  0,70 |---------------------------0,89          Uma correlação forte\n\t          0,90 |---------------------------1,00          Uma correlação muito forte\n\nr = sigla representante do Coeficiente de Correlação\nn = números de elementos \n∑ = somatório \nx = elementos do Eixo X\ny = elementos do Eixo Y\n\n                                           ########## Coeficiente de Determinação: ##########\n\nO Coeficiente de Determinação é uma medida que serve para descrever a proporção da variável y, ou seja, eleva-se o \"r\" ao quadrado. \n\nR² = é a razão da variação explicada e a variação total\n \n                                           ########## Equação da Reta de Regressão: ##########\n\nY = valor da variável dependente da i-ésima tentativa ou observação.\na = primeiro parâmetro da equação de regressão, o qual indica o valor de Y quando X = 0;\nb = segundo o parâmetro da equação de regressão, chamado de coeficiente de regressão, que indica a inclinação da linha de regressão.");

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jTextPane2, org.jdesktop.beansbinding.ELProperty.create("${editable}false"), jTextPane2, org.jdesktop.beansbinding.BeanProperty.create("editable"));
        bindingGroup.addBinding(binding);

        jScrollPane3.setViewportView(jTextPane2);

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 661, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 320, Short.MAX_VALUE)
                .addContainerGap())
        );

        jtCoeficientes.addTab("Ajuda", new javax.swing.ImageIcon(getClass().getResource("/resources/imagens/help.png")), jPanel6); // NOI18N

        javax.swing.GroupLayout plCamposLayout = new javax.swing.GroupLayout(plCampos);
        plCampos.setLayout(plCamposLayout);
        plCamposLayout.setHorizontalGroup(
            plCamposLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(plCamposLayout.createSequentialGroup()
                .addComponent(jtCoeficientes, javax.swing.GroupLayout.PREFERRED_SIZE, 686, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        plCamposLayout.setVerticalGroup(
            plCamposLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(plCamposLayout.createSequentialGroup()
                .addComponent(jtCoeficientes, javax.swing.GroupLayout.PREFERRED_SIZE, 372, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(plCampos, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(plCampos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btRemoverYActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btRemoverYActionPerformed
        if (listY.getSelectedIndex() != -1) {
            int index = listY.getSelectedIndex();
            listModelY.remove(index);
            limparInstancia();
        }
    }//GEN-LAST:event_btRemoverYActionPerformed

    private void btAdicionarYActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAdicionarYActionPerformed
        adicionarOuAlterarY();
    }//GEN-LAST:event_btAdicionarYActionPerformed

    private void btRemoverXActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btRemoverXActionPerformed
        if (listX.getSelectedIndex() != -1) {
            int index = listX.getSelectedIndex();
            listModelX.remove(index);
            limparInstancia();
           
        }
    }//GEN-LAST:event_btRemoverXActionPerformed

    private void btAdicionarXActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAdicionarXActionPerformed
        adicionarOuAlterarX();
    }//GEN-LAST:event_btAdicionarXActionPerformed

    private void btExecutarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btExecutarActionPerformed
        if (validarLista()) {
            Grafico g = new Grafico();
            g.iniciar(arrayX(), arrayY());
            g.setVisible(true);
            if (tfCoeficienteR.getValue().doubleValue() >= 0.00 && tfCoeficienteR.getValue().doubleValue() <= 0.19) {
                tfCoeficienteR.setToolTipText("Correlação bem fraca");
                tfCoeficienteR.setValue(calculo.r(new BigDecimal(sizeListX()), listX(), listY()));
            }
            if (tfCoeficienteR.getValue().doubleValue() >= 0.20 && tfCoeficienteR.getValue().doubleValue() <= 0.39) {
                tfCoeficienteR.setToolTipText("Correlação fraca");
                tfCoeficienteR.setValue(calculo.r(new BigDecimal(sizeListX()), listX(), listY()));
            }
            if (tfCoeficienteR.getValue().doubleValue() >= 0.40 && tfCoeficienteR.getValue().doubleValue() <= 0.69) {
                tfCoeficienteR.setToolTipText("Correlação moderada");
                tfCoeficienteR.setValue(calculo.r(new BigDecimal(sizeListX()), listX(), listY()));
            }
            if (tfCoeficienteR.getValue().doubleValue() >= 0.70 && tfCoeficienteR.getValue().doubleValue() <= 0.89) {
                tfCoeficienteR.setToolTipText("Correlação forte");
                tfCoeficienteR.setValue(calculo.r(new BigDecimal(sizeListX()), listX(), listY()));
            }
            if (tfCoeficienteR.getValue().doubleValue() >= 0.90 && tfCoeficienteR.getValue().doubleValue() <= 1.00) {
                tfCoeficienteR.setToolTipText("Correlação muito forte");
                tfCoeficienteR.setValue(calculo.r(new BigDecimal(sizeListX()), listX(), listY()));
            }
            if (tfCoeficienteR.getValue().doubleValue() >= 0.00 && tfCoeficienteR.getValue().doubleValue() <= 100.00) {
                tfDeterminacao.setToolTipText("<html>" + calculo.rDois(new BigDecimal(sizeListX()), listX(), listY()).setScale(2, RoundingMode.HALF_UP)
                        + "% pode ser explicado pela relação de regressão entre X e Y<br>"
                        + BigDecimal.valueOf(100.00).subtract(calculo.rDois(new BigDecimal(sizeListX()), listX(), listY()).setScale(2, RoundingMode.HALF_UP))
                        + "% pode ser explicado por outros fatores ou erros amostrais</html>");
            }

            tfDeterminacao.setValue(calculo.rDois(new BigDecimal(sizeListX()), listX(), listY()));
            tfParamB.setValue(calculo.b(new BigDecimal(sizeListX()), listX(), listY()));
            tfParamA.setValue(calculo.a(new BigDecimal(sizeListX()), listX(), listY()));
            tfParamA1.setValue(calculo.a(new BigDecimal(sizeListX()), listX(), listY()));
            tfParamB1.setValue(calculo.b(new BigDecimal(sizeListX()), listX(), listY()));
            //Valor Estimado exibe valor do cálculo
            //tfRegressaoYeX.setValue(calculo.y(new BigDecimal(sizeListX()), listX(), listY()));
           
            adicionar();
        }
    }//GEN-LAST:event_btExecutarActionPerformed

    private void btCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelarActionPerformed
        this.dispose();
    }//GEN-LAST:event_btCancelarActionPerformed

    private void tfValorXActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfValorXActionPerformed
       
    }//GEN-LAST:event_tfValorXActionPerformed

    private void tfValorXKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfValorXKeyReleased
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            WindowUtils.setEnterButton(btAdicionarX);
        }
    }//GEN-LAST:event_tfValorXKeyReleased

    private void btAdicionarXKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_btAdicionarXKeyPressed
        tfValorX.requestFocus();
    }//GEN-LAST:event_btAdicionarXKeyPressed

    private void tfValorXKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfValorXKeyPressed

    }//GEN-LAST:event_tfValorXKeyPressed

    private void jLabel6MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel6MouseReleased

    }//GEN-LAST:event_jLabel6MouseReleased

    private void btAdicionarYKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_btAdicionarYKeyPressed
        tfValorY.requestFocus();
    }//GEN-LAST:event_btAdicionarYKeyPressed

    private void btRemoverXKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_btRemoverXKeyPressed
        tfValorX.requestFocus();

    }//GEN-LAST:event_btRemoverXKeyPressed

    private void plCamposRKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_plCamposRKeyPressed


    }//GEN-LAST:event_plCamposRKeyPressed

    private void plCamposRMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_plCamposRMouseReleased

    }//GEN-LAST:event_plCamposRMouseReleased

    private void btUltimaListaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btUltimaListaActionPerformed
        int sizeX = listX.getModel().getSize();
        int sizeY = listY.getModel().getSize();

        if (sizeX == 0 && sizeY == 0) {
            DAOEixoX daoX = new DAOEixoX();
            Integer codigo = daoX.getMaxEixoX();

            EixoX eixoX = daoX.consultar(codigo);
            if (eixoX != null) {
                for (ItemEixoX i : eixoX.getItensX()) {
                    listModelX.addElement(i);
                    listX.setModel(listModelX);
                }
            } else {
                JOptionPane.showMessageDialog(null, "Informe a msg de X nçao existe");
            }
            DAOEixoY daoY = new DAOEixoY();
            Integer codigo1 = daoY.getMaxEixoY();

            EixoY eixoY = daoY.consultar(codigo1);
            if (eixoY != null) {
                for (ItemEixoY i : eixoY.getItensY()) {
                    listModelY.addElement(i);
                    listY.setModel(listModelY);
                }
            } else {
                JOptionPane.showMessageDialog(null, "Informe a msg de Y nçao existe");
            }
        }

    }//GEN-LAST:event_btUltimaListaActionPerformed

    private void btLimparActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btLimparActionPerformed
        limparInstancia();
        listModelX.clear();
        listModelY.clear();
        tfValorX.setValue(BigDecimal.ZERO);
        tfValorX.setValue(BigDecimal.ZERO);
    }//GEN-LAST:event_btLimparActionPerformed

    private void tfParamB1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfParamB1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfParamB1ActionPerformed

    private void tfParamA1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfParamA1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfParamA1ActionPerformed

    private void btSimularRegressaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSimularRegressaoActionPerformed
        BigDecimal valorA = calculo.a(new BigDecimal(sizeListX()), listX(), listY());
        BigDecimal valorB = calculo.b(new BigDecimal(sizeListX()), listX(), listY());
        BigDecimal valorX = tfResultadoRegressaoX.getValue();
        tfRegressaoYeX.setValue(valorA.add((valorB.multiply(valorX, MathContext.DECIMAL32))));
    }//GEN-LAST:event_btSimularRegressaoActionPerformed

    private void tfResultadoRegressaoXKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfResultadoRegressaoXKeyReleased
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            WindowUtils.setEnterButton(btSimularRegressao);
        }
    }//GEN-LAST:event_tfResultadoRegressaoXKeyReleased

    private void tfResultadoRegressaoXActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfResultadoRegressaoXActionPerformed
        btSimularRegressao.requestFocus();
    }//GEN-LAST:event_tfResultadoRegressaoXActionPerformed

    private void tfParamBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfParamBActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfParamBActionPerformed

    private void tfParamAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfParamAActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfParamAActionPerformed

    private void tfRegressaoYeXActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfRegressaoYeXActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfRegressaoYeXActionPerformed

    private void tfDeterminacaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfDeterminacaoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfDeterminacaoActionPerformed

    private void tfCoeficienteRActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfCoeficienteRActionPerformed

    }//GEN-LAST:event_tfCoeficienteRActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new TelaPrincipal().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btAdicionarX;
    private javax.swing.JButton btAdicionarY;
    private javax.swing.JButton btCancelar;
    private javax.swing.JButton btExecutar;
    private javax.swing.JButton btLimpar;
    private javax.swing.JButton btRemoverX;
    private javax.swing.JButton btRemoverY;
    private javax.swing.JButton btSimularRegressao;
    private javax.swing.JButton btUltimaLista;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPopupMenu jPopupMenu1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JTextPane jTextPane2;
    private javax.swing.JTabbedPane jtCoeficientes;
    private javax.swing.JList listX;
    private javax.swing.JList listY;
    private javax.swing.JPanel plCampos;
    private javax.swing.JLabel plCamposR;
    private javax.swing.JPanel plCamposX;
    private javax.swing.JPanel plCamposX1;
    private javax.swing.JPanel plCamposY;
    private javax.swing.JPanel plCamposY1;
    private com.zap.arca.JADecimalFormatField tfCoeficienteR;
    private com.zap.arca.JADecimalFormatField tfDeterminacao;
    private com.zap.arca.JADecimalFormatField tfParamA;
    private com.zap.arca.JADecimalFormatField tfParamA1;
    private com.zap.arca.JADecimalFormatField tfParamB;
    private com.zap.arca.JADecimalFormatField tfParamB1;
    private com.zap.arca.JADecimalFormatField tfRegressaoYeX;
    private com.zap.arca.JADecimalFormatField tfResultadoRegressaoX;
    private com.zap.arca.JADecimalFormatField tfValorX;
    private com.zap.arca.JADecimalFormatField tfValorY;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    private void adicionarOuAlterarX() {
        if (itemEixoX == null) {
            itemEixoX = new ItemEixoX(new ItemEixoXPK(null, listX.getModel().getSize() + 1));
            itemEixoX.setValorEixoX(tfValorX.getValue());
        } else {
            itemEixoX.getpK().setIdentificador(((ItemEixoX) listX.getSelectedValue()).getpK().getIdentificador());
            itemEixoX.setValorEixoX(tfValorX.getValue());
        }

        if (validarX(itemEixoX.getpK().getIdentificador())) {
            listModelX.addElement(itemEixoX);
            listX.setModel(listModelX);
        } else {
            listX.setModel(listModelX);
        }
        tfValorX.setValue(BigDecimal.ZERO);
        limparInstancia();
    }

    private void adicionarOuAlterarY() {
        if (itemEixoY == null) {
            itemEixoY = new ItemEixoY(new ItemEixoYPK(null, listY.getModel().getSize() + 1));
            itemEixoY.setValorEixoY(tfValorY.getValue());
        } else {

            itemEixoY.getpK().setIdentificador(((ItemEixoY) listY.getSelectedValue()).getpK().getIdentificador());
            itemEixoY.setValorEixoY(tfValorY.getValue());

        }

        if (validarY(itemEixoY.getpK().getIdentificador())) {
            listModelY.addElement(itemEixoY);
            listY.setModel(listModelY);
        } else {
            listY.setModel(listModelY);
        }
        tfValorY.setValue(BigDecimal.ZERO);
        limparInstancia();
    }

    private boolean validarX(int codigo) {
        int tamanhoLista = listX.getModel().getSize();
        for (int i = 0; i < tamanhoLista; i++) {
            ItemEixoX cod = (ItemEixoX) listX.getModel().getElementAt(i);
            if (cod.getpK().getIdentificador() == codigo) {
                return false;
            }
        }
        return true;
    }

    private boolean validarY(int codigo) {
        int tamanhoLista = listY.getModel().getSize();
        for (int i = 0; i < tamanhoLista; i++) {
            ItemEixoY cod = (ItemEixoY) listY.getModel().getElementAt(i);
            if (cod.getpK().getIdentificador() == codigo) {
                return false;
            }
        }
        return true;
    }

    public void configurarEvento() {
        listX.addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent e) {
                if (e.getValueIsAdjusting()) {
                    btAdicionarX.setText("Alterar");
                    itemEixoX = (ItemEixoX) listX.getSelectedValue();
                    tfValorX.setValue(itemEixoX.getValorEixoX());
                }
            }
        });

        listY.addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent e) {
                if (e.getValueIsAdjusting()) {
                    btAdicionarY.setText("Alterar");
                    itemEixoY = (ItemEixoY) listY.getSelectedValue();
                    tfValorY.setValue(itemEixoY.getValorEixoY().doubleValue());
                }
            }
        });
    }

    public void limparInstancia() {
        itemEixoX = null;
        itemEixoY = null;
        btAdicionarX.setText("Adicionar");
        btAdicionarY.setText("Adicionar");
    }

    public double[] arrayX() {
        int tamanhoLista = listX.getModel().getSize();
        double[] x = new double[tamanhoLista];
        for (int i = 0; i < tamanhoLista; i++) {
            ItemEixoX e = (ItemEixoX) listX.getModel().getElementAt(i);
            double valor = Double.valueOf(e.getValorEixoX().doubleValue());
            x[i] = valor;
        }
        return x;
    }

    public double[] arrayY() {
        int tamanhoLista = listY.getModel().getSize();
        double[] y = new double[tamanhoLista];
        for (int i = 0; i < tamanhoLista; i++) {
            ItemEixoY e = (ItemEixoY) listY.getModel().getElementAt(i);
            double valor = e.getValorEixoY().doubleValue();
            y[i] = valor;
        }
        return y;
    }

    public int sizeListX() {
        return listX.getModel().getSize();
    }

    private boolean validarLista() {
        int sizeX = listX.getModel().getSize();
        int sizeY = listY.getModel().getSize();

        if (sizeX == 0 && sizeY == 0) {
            JOptionPane.showMessageDialog(null, "Entre com os valores de X e Y para gerar o diagrama de dispersão e a reta de regressão", "Atenção", 2);
            return false;
        }
        if(sizeX == 0){
            btRemoverX.setEnabled(false);
            return false;
        }
        if (sizeX > sizeY) {
            JOptionPane.showMessageDialog(null, "A quantidade de elementos de Y deve ser igual a de X.", "Atenção", 2);
            listX.setSelectedValue(listModelX.lastElement(), true);
            return false;
        } else if (sizeY > sizeX) {
            JOptionPane.showMessageDialog(null, "A quantidade de elementos de X deve ser igual a de Y.", "Atenção", 2);
            listY.setSelectedValue(listModelY.lastElement(), true);
            return false;
        }

        return true;
    }

    public List<Double> listX() {
        List<Double> list = new ArrayList<>();
        int tamanhoLista = listX.getModel().getSize();
        double[] x = new double[tamanhoLista];
        for (int i = 0; i < tamanhoLista; i++) {
            ItemEixoX e = (ItemEixoX) listX.getModel().getElementAt(i);
            double valor = e.getValorEixoX().doubleValue();
            x[i] = valor;
            list.add(x[i]);
        }
        return list;
    }

    public List<Double> listY() {
        List<Double> list = new ArrayList<>();
        int tamanhoLista = listY.getModel().getSize();
        double[] y = new double[tamanhoLista];
        for (int i = 0; i < tamanhoLista; i++) {
            ItemEixoY e = (ItemEixoY) listY.getModel().getElementAt(i);
            double valor = e.getValorEixoY().doubleValue();
            y[i] = valor;
            list.add(y[i]);
        }
        return list;
    }

    public void adicionar() {
        EixoX eixoX = new EixoX();
        EixoY eixoY = new EixoY();
        List<ItemEixoY> eixoYs = new ArrayList<>();
        for (int i = 0; i < listY.getModel().getSize(); i++) {
            ItemEixoY e = (ItemEixoY) listY.getModel().getElementAt(i);
            e.getpK().setEixoY(eixoY);
            e.setEixoY(eixoY);
            eixoYs.add(e);
        }
        eixoY.setItensY(eixoYs);
        List<ItemEixoX> eixoXs = new ArrayList<>();
        for (int i = 0; i < listX.getModel().getSize(); i++) {
            ItemEixoX e = (ItemEixoX) listX.getModel().getElementAt(i);
            e.getpK().setEixoX(eixoX);
            e.setEixoX(eixoX);
            eixoXs.add(e);

        }
        eixoX.setItensX(eixoXs);
        DAOEixoX daoex = new DAOEixoX();
        daoex.adicionar(eixoX);
        DAOEixoY daoey = new DAOEixoY();
        daoey.adicionar(eixoY);
    }
}
